﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using PlanningGIS.ManageUtility.Modules;

namespace PlanningGIS.ManageUtility.DataAccess
{
    /// <summary>
    /// 角色数据操作类
    /// </summary>
    public class RoleAccess
    {
        /// <summary>
        /// 获取指定key值的配置项
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        public static DataTable GetRoleTag()
        {
            return ManageHelper.DBContext.GetDataTable("select id,name from ROLE ");
        }

        /// <summary>
        /// 获取角色关联的数据资源信息
        /// </summary>
        /// <param name="roleid">角色编号</param>
        /// <returns></returns>
        public static List<Role_Rel> GetRoleResRel(string roleid)
        {
            return GetRoleRel(roleid, "1");
        }

        /// <summary>
        /// 获取角色关联的功能菜单信息
        /// </summary>
        /// <param name="roleid">角色编号</param>
        /// <returns></returns>
        public static List<Role_Rel> GetRoleFuncRel(string roleid)
        {
            return GetRoleRel(roleid, "2");
        }

        /// <summary>
        /// 获取角色关联的TOC信息
        /// </summary>
        /// <param name="roleid">角色编号</param>
        /// <returns></returns>
        public static List<Role_Rel> GetRoleTocRel(string roleid)
        {
            return GetRoleRel(roleid, "3");
        }

        /// <summary>
        /// 获取角色关联的配图模板信息
        /// </summary>
        /// <param name="roleid">角色编号</param>
        /// <returns></returns>
        public static List<Role_Rel> GetRoleMXDRel(string roleid)
        {
            return GetRoleRel(roleid, "4");
        }

        /// <summary>
        /// 获取角色关联的信息
        /// </summary>
        /// <param name="roleid">角色编号</param>
        /// <param name="reltype">关联的类型：1数据权限；2功能权限；3Toc右键菜单；4模板配置</param>
        /// <returns></returns>
        public static List<Role_Rel> GetRoleRel(string roleid, string reltype)
        {
            Dictionary<string, dynamic> where = new Dictionary<string, dynamic>();
            where.Add("roleid", roleid);
            where.Add("reltype", reltype);
            return ManageHelper.DBContext.GetAllEntry<Role_Rel>(where);
        }
    }
}
